{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "45e99432",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/pmo/miniconda3/envs/BNN/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "import os, math, random\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from typing import Tuple\n",
    "\n",
    "import torch\n",
    "import torch.nn as nn\n",
    "import torch.nn.functional as F\n",
    "from torch.utils.data import Dataset, DataLoader\n",
    "from sklearn.model_selection import KFold\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn.metrics import accuracy_score, f1_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dead9379",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Device: cuda\n"
     ]
    }
   ],
   "source": [
    "# -------------------------- 1. 初始化设置（与原代码一致）--------------------------\n",
    "SEED = 42\n",
    "random.seed(SEED); np.random.seed(SEED); torch.manual_seed(SEED)\n",
    "DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n",
    "print(\"Device:\", DEVICE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c4a46137",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 976 entries, 0 to 975\n",
      "Data columns (total 48 columns):\n",
      " #   Column                                 Non-Null Count  Dtype  \n",
      "---  ------                                 --------------  -----  \n",
      " 0   Activate Ester_E HOMO (eV)             976 non-null    float64\n",
      " 1   Activate Ester_E LUMO (eV)             976 non-null    float64\n",
      " 2   Activate Ester_Dipole (debye)          976 non-null    float64\n",
      " 3   Activate Ester_Acc. Area (Å²)          976 non-null    float64\n",
      " 4   Activate Ester_Max ElPot (kJ/mol)      976 non-null    float64\n",
      " 5   Activate Ester_Min ElPot (kJ/mol)      976 non-null    float64\n",
      " 6   Activate Ester_Min LocIonPot (kJ/mol)  976 non-null    float64\n",
      " 7   Activate Ester_Polar Area(75) (Å²)     976 non-null    float64\n",
      " 8   Activate Ester_Log P                   976 non-null    float64\n",
      " 9   Activate Ester_Polarizability          976 non-null    float64\n",
      " 10  Activate Ester_Mulliken(Hx)            976 non-null    float64\n",
      " 11  Activate Ester_ExposedArea(Hx) (Å²)    976 non-null    float64\n",
      " 12  Activate Ester_Electrostatic(Cx)       976 non-null    float64\n",
      " 13  Activate Ester_Mulliken(Cx)            976 non-null    float64\n",
      " 14  Activate Ester_Natural(Cx)             976 non-null    float64\n",
      " 15  Activate Ester_ChemShift(Cx)           976 non-null    float64\n",
      " 16  Activate Ester_ExposedArea(Cx) (Å²)    976 non-null    float64\n",
      " 17  Activate Ester_Length(Bondx) Å         976 non-null    float64\n",
      " 18  Activate Ester_Mulliken(Cy)            976 non-null    float64\n",
      " 19  Activate Ester_Natural(Cy)             976 non-null    float64\n",
      " 20  Activate Ester_ChemShift(Cy)           976 non-null    float64\n",
      " 21  Activate Ester_ExposedArea(Cy) (Å²)    976 non-null    float64\n",
      " 22  Activate Ester_Electrostatic(Ox)       976 non-null    float64\n",
      " 23  Activate Ester_Mulliken(Ox)            976 non-null    float64\n",
      " 24  Activate Ester_Natural(Ox)             976 non-null    float64\n",
      " 25  Activate Ester_ChemShift(Ox)           976 non-null    float64\n",
      " 26  Activate Ester_ExposedArea(Ox) (Å²)    976 non-null    float64\n",
      " 27  Activate Ester_Electrostatic(Oy)       976 non-null    float64\n",
      " 28  Activate Ester_Mulliken(Oy)            976 non-null    float64\n",
      " 29  Activate Ester_ChemShift(Oy)           976 non-null    float64\n",
      " 30  Activate Ester_ExposedArea(Oy) (Å²)    976 non-null    float64\n",
      " 31  Activate Ester_Length(Bondz) Å         976 non-null    float64\n",
      " 32  Activate Ester_Length(Bondw) Å         976 non-null    float64\n",
      " 33  Activate Ester_Mulliken(Bondw)         976 non-null    float64\n",
      " 34  Base-pKa                               976 non-null    float64\n",
      " 35  Base-Dipole (debye)                    976 non-null    float64\n",
      " 36  Base-Acc. Area (Å²)                    976 non-null    float64\n",
      " 37  Base-Log P                             976 non-null    float64\n",
      " 38  Base-Electrostatic(Nx)                 976 non-null    float64\n",
      " 39  Base-Mulliken(Nx)                      976 non-null    float64\n",
      " 40  Solvent_Refractive index               976 non-null    float64\n",
      " 41  Solvent_Dielectric constant            976 non-null    float64\n",
      " 42  Solvent_Melting point (°C)             976 non-null    int64  \n",
      " 43  Solvent_Boiling point (°C)             976 non-null    int64  \n",
      " 44  Solvent_Viscosity (cP)                 976 non-null    float64\n",
      " 45  Solvent_logP (partition coeff.)        976 non-null    float64\n",
      " 46  Solvent_HBD                            976 non-null    float64\n",
      " 47  label.1                                976 non-null    int64  \n",
      "dtypes: float64(45), int64(3)\n",
      "memory usage: 366.1 KB\n"
     ]
    }
   ],
   "source": [
    "# -------------------------- 2. 数据读取与预处理（分类任务适配）--------------------------\n",
    "# 读取数据（需确保Excel中存在分类标签列，此处假设标签列为'class_label'）\n",
    "exp_file = \"/home/pmo/linhan/attention-based-model/project/Dataset.xlsx\"\n",
    "exp_sheet = \"exp\"                                \n",
    "df = pd.read_excel(exp_file, exp_sheet, header = 0)\n",
    "df = df.iloc[:,7:]  # 保留第14列后的数据\n",
    "df.info(verbose=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a409ab46",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分类任务核心：分离特征与【分类标签】（需替换为你的实际标签列名）\n",
    "LABEL_COL = 'label.1'  # ！！关键：替换为你的分类标签列名（如是否活性、类别1/2/3）\n",
    "feature_cols = [c for c in df.columns if c != LABEL_COL]\n",
    "X = df[feature_cols].values.astype(np.float32)\n",
    "y = df[LABEL_COL].values.astype(np.int64)  # 分类标签用int64（适配PyTorch交叉熵）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "64c514d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "X shape: (976, 47), y shape: (976,)\n",
      "Label distribution: [588 388]\n",
      "Number of classes: 2\n"
     ]
    }
   ],
   "source": [
    "# 检查标签分布（确保分类任务合理性）\n",
    "print(f\"X shape: {X.shape}, y shape: {y.shape}\")\n",
    "print(f\"Label distribution: {np.bincount(y)}\")  # 输出每个类别的样本数\n",
    "num_classes = len(np.unique(y))  # 自动获取类别数（无需手动指定）\n",
    "print(f\"Number of classes: {num_classes}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "cedd5082",
   "metadata": {},
   "outputs": [],
   "source": [
    "# -------------------------- 3. 数据集类（分类任务无需修改，仅传递标签）--------------------------\n",
    "class TabDataset(Dataset):\n",
    "    def __init__(self, X: np.ndarray, y: np.ndarray):\n",
    "        self.X = torch.from_numpy(X)\n",
    "        self.y = torch.from_numpy(y)  # 分类标签为int64，无需reshape\n",
    "    \n",
    "    def __len__(self):\n",
    "        return len(self.X)\n",
    "    \n",
    "    def __getitem__(self, idx):\n",
    "        return self.X[idx], self.y[idx]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2999ae18",
   "metadata": {},
   "outputs": [],
   "source": [
    "# -------------------------- 4. 模型定义（核心修改：回归→分类，新增注意力权重提取）--------------------------\n",
    "class FeatureAttention(nn.Module):\n",
    "    \"\"\"特征注意力模块（不变）：输出特征权重w，用于后续关键参数筛选\"\"\"\n",
    "    def __init__(self, d_in: int, hidden: int = 32):\n",
    "        super().__init__()\n",
    "        self.net = nn.Sequential(\n",
    "            nn.Linear(d_in, hidden),\n",
    "            nn.ReLU(),\n",
    "            nn.Linear(hidden, d_in),\n",
    "            nn.Sigmoid()  # 权重w∈[0,1]，值越大表示特征越重要\n",
    "        )\n",
    "    \n",
    "    def forward(self, x):\n",
    "        w = self.net(x)  # (B, d_in)：每个样本的特征权重\n",
    "        return x * w, w  # ！！新增：返回加权后特征 + 原始权重w（用于后续分析）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "1ea55337",
   "metadata": {},
   "outputs": [],
   "source": [
    "class ClassifierWithAttention(nn.Module):\n",
    "    \"\"\"分类模型（原回归模型修改）：输出类别概率，保留特征注意力\"\"\"\n",
    "    def __init__(self, d_in: int, num_classes: int, width: int = 64, p_drop: float = 0.2):\n",
    "        super().__init__()\n",
    "        self.attn = FeatureAttention(d_in, hidden=32)  # 特征注意力模块\n",
    "        self.mlp = nn.Sequential(\n",
    "            nn.Linear(d_in, width),\n",
    "            nn.ReLU(),\n",
    "            nn.Dropout(p_drop),\n",
    "            nn.Linear(width, width),\n",
    "            nn.ReLU(),\n",
    "            nn.Dropout(p_drop),\n",
    "        )\n",
    "        # ！！核心修改：回归输出（mu/log_var）→ 分类输出（类别概率）\n",
    "        self.head = nn.Linear(width, num_classes)  # 输出维度=类别数\n",
    "    \n",
    "    def forward(self, x):\n",
    "        # ！！新增：获取注意力权重w\n",
    "        x_attended, attn_weights = self.attn(x)  # x_attended：加权后特征；attn_weights：(B, d_in)\n",
    "        h = self.mlp(x_attended)\n",
    "        logits = self.head(h)  # 分类logits（未经过softmax）\n",
    "        return logits, attn_weights  # ！！返回logits（用于损失计算）+ 注意力权重（用于分析）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d6e074da",
   "metadata": {},
   "outputs": [],
   "source": [
    "def total_loss(logits, y_true, attn_weights, sparse_lambda=1e-3):\n",
    "    \"\"\"\n",
    "    总损失 = 分类交叉熵损失 + 注意力权重的L1稀疏惩罚\n",
    "    Args:\n",
    "        logits: 模型输出的logits (B, num_classes)\n",
    "        y_true: 真实标签 (B,)\n",
    "        attn_weights: 注意力权重 (B, d_in)\n",
    "        sparse_lambda: 稀疏惩罚系数（越大，稀疏性越强，需调参）\n",
    "    Returns:\n",
    "        total_loss: 带稀疏惩罚的总损失\n",
    "    \"\"\"\n",
    "    # 1. 分类损失（交叉熵）\n",
    "    ce_loss = F.cross_entropy(logits, y_true)\n",
    "    # 2. L1稀疏惩罚（对每个样本的注意力权重取绝对值求和，再平均）\n",
    "    # 目的：让每个样本的权重尽可能集中在少数特征上，大部分权重趋近于0\n",
    "    sparse_loss = attn_weights.abs().mean()  # (B, d_in) → (B,) → 标量\n",
    "    # 3. 总损失（分类损失 + 稀疏惩罚）\n",
    "    return ce_loss + sparse_lambda * sparse_loss"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "fc4f3d17",
   "metadata": {},
   "outputs": [],
   "source": [
    "def train_one_fold(X_tr, y_tr, X_val, y_val, feature_names, num_classes,\n",
    "                   epochs=300, batch_size=32, lr=1e-3, patience=30, sparse_lambda=1e-3):\n",
    "    \"\"\"\n",
    "    单折训练：加入sparse_lambda参数控制稀疏惩罚强度\n",
    "    \"\"\"\n",
    "    # 数据标准化与加载（不变）\n",
    "    scaler = StandardScaler().fit(X_tr)\n",
    "    X_tr_s = scaler.transform(X_tr)\n",
    "    X_val_s = scaler.transform(X_val)\n",
    "    ds_tr = TabDataset(X_tr_s, y_tr)\n",
    "    ds_val = TabDataset(X_val_s, y_val)\n",
    "    dl_tr = DataLoader(ds_tr, batch_size=batch_size, shuffle=True, drop_last=False)\n",
    "    dl_val = DataLoader(ds_val, batch_size=256, shuffle=False, drop_last=False)\n",
    "\n",
    "    # 模型与优化器（不变）\n",
    "    model = ClassifierWithAttention(\n",
    "        d_in=X_tr.shape[1], num_classes=num_classes, width=64, p_drop=0.2\n",
    "    ).to(DEVICE)\n",
    "    opt = torch.optim.Adam(model.parameters(), lr=lr, weight_decay=1e-4)\n",
    "\n",
    "    # 训练循环（核心：使用带稀疏惩罚的总损失）\n",
    "    best_acc, best_state, wait = 0.0, None, 0\n",
    "    for ep in range(1, epochs+1):\n",
    "        model.train()\n",
    "        tr_total_loss = 0.0\n",
    "        tr_ce_loss = 0.0  # 纯分类损失（用于监控）\n",
    "        tr_sparse_loss = 0.0  # 稀疏惩罚损失（用于监控）\n",
    "        \n",
    "        for xb, yb in dl_tr:\n",
    "            xb, yb = xb.to(DEVICE), yb.to(DEVICE)\n",
    "            logits, attn_w = model(xb)\n",
    "            \n",
    "            # 计算带稀疏惩罚的总损失\n",
    "            loss = total_loss(logits, yb, attn_w, sparse_lambda=sparse_lambda)\n",
    "            # 单独计算分类损失和稀疏损失（仅用于日志监控）\n",
    "            ce_loss = F.cross_entropy(logits, yb)\n",
    "            sparse_loss = attn_w.abs().mean()\n",
    "            \n",
    "            # 反向传播与优化\n",
    "            opt.zero_grad(); loss.backward(); opt.step()\n",
    "            \n",
    "            # 累加损失（按样本数加权）\n",
    "            tr_total_loss += loss.item() * len(xb)\n",
    "            tr_ce_loss += ce_loss.item() * len(xb)\n",
    "            tr_sparse_loss += sparse_loss.item() * len(xb)\n",
    "        \n",
    "        # 计算平均损失（每样本）\n",
    "        tr_total_loss /= len(ds_tr)\n",
    "        tr_ce_loss /= len(ds_tr)\n",
    "        tr_sparse_loss /= len(ds_tr)\n",
    "\n",
    "        # 验证阶段（不变，仅用分类损失评估性能）\n",
    "        model.eval()\n",
    "        with torch.no_grad():\n",
    "            y_pred_list, y_true_list = [], []\n",
    "            for xb, yb in dl_val:\n",
    "                xb = xb.to(DEVICE)\n",
    "                logits, _ = model(xb)\n",
    "                y_pred = torch.argmax(logits, dim=1).cpu().numpy()\n",
    "                y_pred_list.append(y_pred)\n",
    "                y_true_list.append(yb.numpy())\n",
    "        y_pred = np.concatenate(y_pred_list)\n",
    "        y_true = np.concatenate(y_true_list)\n",
    "        val_acc = accuracy_score(y_true, y_pred)\n",
    "        val_f1 = f1_score(y_true, y_pred, average='weighted')\n",
    "\n",
    "        # 早停机制（不变）\n",
    "        if val_acc > best_acc + 1e-4:\n",
    "            best_acc = val_acc\n",
    "            best_state = {k: v.cpu().clone() for k, v in model.state_dict().items()}\n",
    "            wait = 0\n",
    "        else:\n",
    "            wait += 1\n",
    "\n",
    "        # 日志输出（新增稀疏损失监控）\n",
    "        if ep % 25 == 0 or ep == 1:\n",
    "            print(f\"[Epoch {ep:03d}] \"\n",
    "                  f\"total_loss={tr_total_loss:.4f} | \"\n",
    "                  f\"ce_loss={tr_ce_loss:.4f} | \"\n",
    "                  f\"sparse_loss={tr_sparse_loss:.4f} | \"\n",
    "                  f\"val_acc={val_acc:.4f} | \"\n",
    "                  f\"val_f1={val_f1:.4f} (best acc {best_acc:.4f})\")\n",
    "\n",
    "        if wait >= patience:\n",
    "            print(f\"Early stop at epoch {ep}, best val Acc={best_acc:.4f}\")\n",
    "            break\n",
    "\n",
    "    # 计算当前折的特征平均权重（用于后续可视化）\n",
    "    model.load_state_dict(best_state)\n",
    "    model.eval()\n",
    "    with torch.no_grad():\n",
    "        all_attn_w = []\n",
    "        for xb, _ in dl_val:\n",
    "            xb = xb.to(DEVICE)\n",
    "            _, attn_w = model(xb)\n",
    "            all_attn_w.append(attn_w.cpu().numpy())\n",
    "        avg_attn_weights = np.concatenate(all_attn_w).mean(axis=0)\n",
    "        top5_idx = np.argsort(avg_attn_weights)[-5:][::-1]\n",
    "        top5_feat = [feature_names[i] for i in top5_idx]\n",
    "        top5_w = avg_attn_weights[top5_idx]\n",
    "\n",
    "    print(f\"\\n[Fold Best] Top5 Features (Attention Weight):\")\n",
    "    for i, (feat, w) in enumerate(zip(top5_feat, top5_w), 1):\n",
    "        print(f\"  {i}. {feat}: {w:.4f}\")\n",
    "    return model, scaler, best_acc, top5_feat, top5_w, avg_attn_weights  # 新增返回所有特征的平均权重"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "a40db7d6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "==================== Fold 1 ====================\n",
      "[Epoch 001] total_loss=0.6546 | ce_loss=0.6541 | sparse_loss=0.5006 | val_acc=0.5663 | val_f1=0.4095 (best acc 0.5663)\n",
      "[Epoch 025] total_loss=0.2162 | ce_loss=0.2157 | sparse_loss=0.5107 | val_acc=0.7806 | val_f1=0.7762 (best acc 0.8010)\n",
      "Early stop at epoch 41, best val Acc=0.8010\n",
      "\n",
      "[Fold Best] Top5 Features (Attention Weight):\n",
      "  1. Base-Log P: 0.7111\n",
      "  2. Activate Ester_Min ElPot (kJ/mol): 0.6953\n",
      "  3. Activate Ester_Min LocIonPot (kJ/mol): 0.6672\n",
      "  4. Activate Ester_Mulliken(Hx): 0.6653\n",
      "  5. Solvent_Boiling point (°C): 0.6590\n",
      "[Fold 1] Final Acc=0.8010, F1=0.7970\n",
      "\n",
      "==================== Fold 2 ====================\n",
      "[Epoch 001] total_loss=0.6645 | ce_loss=0.6640 | sparse_loss=0.4981 | val_acc=0.5590 | val_f1=0.4008 (best acc 0.5590)\n",
      "[Epoch 025] total_loss=0.1928 | ce_loss=0.1923 | sparse_loss=0.5273 | val_acc=0.7692 | val_f1=0.7679 (best acc 0.7795)\n",
      "[Epoch 050] total_loss=0.1004 | ce_loss=0.0999 | sparse_loss=0.4768 | val_acc=0.7590 | val_f1=0.7588 (best acc 0.8000)\n",
      "Early stop at epoch 68, best val Acc=0.8000\n",
      "\n",
      "[Fold Best] Top5 Features (Attention Weight):\n",
      "  1. Activate Ester_Dipole (debye): 0.6791\n",
      "  2. Activate Ester_Natural(Cx): 0.6659\n",
      "  3. Activate Ester_Max ElPot (kJ/mol): 0.6486\n",
      "  4. Solvent_Melting point (°C): 0.6195\n",
      "  5. Activate Ester_ExposedArea(Cy) (Å²): 0.6155\n",
      "[Fold 2] Final Acc=0.8000, F1=0.7989\n",
      "\n",
      "==================== Fold 3 ====================\n",
      "[Epoch 001] total_loss=0.6747 | ce_loss=0.6742 | sparse_loss=0.4964 | val_acc=0.6103 | val_f1=0.4626 (best acc 0.6103)\n",
      "[Epoch 025] total_loss=0.2226 | ce_loss=0.2221 | sparse_loss=0.5243 | val_acc=0.8667 | val_f1=0.8647 (best acc 0.8667)\n",
      "[Epoch 050] total_loss=0.1055 | ce_loss=0.1050 | sparse_loss=0.4807 | val_acc=0.8205 | val_f1=0.8175 (best acc 0.8667)\n",
      "Early stop at epoch 55, best val Acc=0.8667\n",
      "\n",
      "[Fold Best] Top5 Features (Attention Weight):\n",
      "  1. Solvent_Melting point (°C): 0.7035\n",
      "  2. Solvent_Viscosity (cP): 0.6873\n",
      "  3. Activate Ester_Min LocIonPot (kJ/mol): 0.6680\n",
      "  4. Base-Log P: 0.6666\n",
      "  5. Base-Dipole (debye): 0.6360\n",
      "[Fold 3] Final Acc=0.8667, F1=0.8647\n",
      "\n",
      "==================== Fold 4 ====================\n",
      "[Epoch 001] total_loss=0.6650 | ce_loss=0.6645 | sparse_loss=0.5066 | val_acc=0.6667 | val_f1=0.5675 (best acc 0.6667)\n",
      "[Epoch 025] total_loss=0.2013 | ce_loss=0.2008 | sparse_loss=0.5318 | val_acc=0.8205 | val_f1=0.8213 (best acc 0.8308)\n",
      "[Epoch 050] total_loss=0.1025 | ce_loss=0.1021 | sparse_loss=0.4900 | val_acc=0.8256 | val_f1=0.8251 (best acc 0.8564)\n",
      "Early stop at epoch 66, best val Acc=0.8564\n",
      "\n",
      "[Fold Best] Top5 Features (Attention Weight):\n",
      "  1. Solvent_Melting point (°C): 0.6603\n",
      "  2. Activate Ester_E HOMO (eV): 0.6487\n",
      "  3. Base-Electrostatic(Nx): 0.6448\n",
      "  4. Base-Acc. Area (Å²): 0.6355\n",
      "  5. Solvent_Dielectric constant: 0.6342\n",
      "[Fold 4] Final Acc=0.8564, F1=0.8555\n",
      "\n",
      "==================== Fold 5 ====================\n",
      "[Epoch 001] total_loss=0.6764 | ce_loss=0.6759 | sparse_loss=0.4955 | val_acc=0.7026 | val_f1=0.6447 (best acc 0.7026)\n",
      "[Epoch 025] total_loss=0.2165 | ce_loss=0.2160 | sparse_loss=0.5188 | val_acc=0.8051 | val_f1=0.8045 (best acc 0.8359)\n",
      "Early stop at epoch 33, best val Acc=0.8359\n",
      "\n",
      "[Fold Best] Top5 Features (Attention Weight):\n",
      "  1. Activate Ester_Mulliken(Hx): 0.6656\n",
      "  2. Base-Mulliken(Nx): 0.6318\n",
      "  3. Activate Ester_ExposedArea(Hx) (Å²): 0.6290\n",
      "  4. Activate Ester_ChemShift(Cx): 0.6190\n",
      "  5. Activate Ester_Acc. Area (Å²): 0.6067\n",
      "[Fold 5] Final Acc=0.8359, F1=0.8327\n",
      "\n",
      "==================== CV Summary ====================\n",
      "Accuracy: 0.8320 ± 0.0276\n",
      "Weighted F1: 0.8298 ± 0.0280\n",
      "\n",
      "==================== 稀疏效果统计 ====================\n",
      "总特征数：47\n",
      "权重<0.05的特征数：0\n",
      "权重接近0的特征比例：0.00%\n",
      "权重前5的特征：\n",
      "  Activate Ester_Acc. Area (Å²): 0.4949\n",
      "  Activate Ester_Polarizability: 0.5429\n",
      "  Activate Ester_Mulliken(Bondw): 0.4629\n",
      "  Base-Dipole (debye): 0.5231\n",
      "  Base-Electrostatic(Nx): 0.5729\n"
     ]
    }
   ],
   "source": [
    "# 交叉验证（加入sparse_lambda参数，核心调参项）\n",
    "kf = KFold(n_splits=5, shuffle=True, random_state=SEED)\n",
    "fold_metrics = []\n",
    "all_feat_avg_weights = []  # 存储每折所有特征的平均权重，用于后续统计\n",
    "sparse_lambda = 1e-3  # 稀疏惩罚系数（关键超参，建议尝试1e-4~1e-2）\n",
    "\n",
    "for i, (tr_idx, val_idx) in enumerate(kf.split(X), 1):\n",
    "    print(f\"\\n==================== Fold {i} ====================\")\n",
    "    X_tr, y_tr = X[tr_idx], y[tr_idx]\n",
    "    X_val, y_val = X[val_idx], y[val_idx]\n",
    "    \n",
    "    # 训练时传入稀疏惩罚系数\n",
    "    model, scaler, best_acc, top5_feat, top5_w, avg_attn = train_one_fold(\n",
    "        X_tr, y_tr, X_val, y_val,\n",
    "        feature_names=feature_cols,\n",
    "        num_classes=num_classes,\n",
    "        epochs=300,\n",
    "        batch_size=32,\n",
    "        lr=1e-3,\n",
    "        patience=30,\n",
    "        sparse_lambda=sparse_lambda  # 控制稀疏性\n",
    "    )\n",
    "    \n",
    "    # 验证集评估（不变）\n",
    "    X_val_s = scaler.transform(X_val)\n",
    "    with torch.no_grad():\n",
    "        logits, _ = model(torch.from_numpy(X_val_s).to(DEVICE))\n",
    "        y_pred = torch.argmax(logits, dim=1).cpu().numpy()\n",
    "    acc, f1 = accuracy_score(y_val, y_pred), f1_score(y_val, y_pred, average='weighted')\n",
    "    fold_metrics.append((acc, f1))\n",
    "    all_feat_avg_weights.append(avg_attn)  # 收集当前折所有特征的平均权重\n",
    "    print(f\"[Fold {i}] Final Acc={acc:.4f}, F1={f1:.4f}\")\n",
    "\n",
    "# 交叉验证结果汇总\n",
    "print(\"\\n==================== CV Summary ====================\")\n",
    "acc_list = [m[0] for m in fold_metrics]\n",
    "f1_list = [m[1] for m in fold_metrics]\n",
    "print(f\"Accuracy: {np.mean(acc_list):.4f} ± {np.std(acc_list):.4f}\")\n",
    "print(f\"Weighted F1: {np.mean(f1_list):.4f} ± {np.std(f1_list):.4f}\")\n",
    "\n",
    "# -------------------------- 验证稀疏效果：统计权重接近0的特征比例 --------------------------\n",
    "# 计算所有折中特征的平均权重（最终权重）\n",
    "final_all_feat_avg = np.mean(all_feat_avg_weights, axis=0)  # (d_in,)\n",
    "# 定义“接近0”的阈值（如权重<0.05视为接近0）\n",
    "zero_threshold = 0.05\n",
    "zero_feat_count = sum(final_all_feat_avg < zero_threshold)\n",
    "zero_feat_ratio = zero_feat_count / len(final_all_feat_avg)\n",
    "\n",
    "print(f\"\\n==================== 稀疏效果统计 ====================\")\n",
    "print(f\"总特征数：{len(final_all_feat_avg)}\")\n",
    "print(f\"权重<{zero_threshold}的特征数：{zero_feat_count}\")\n",
    "print(f\"权重接近0的特征比例：{zero_feat_ratio:.2%}\")\n",
    "print(f\"权重前5的特征：\")\n",
    "for i, (feat, w) in enumerate(zip(feature_cols, final_all_feat_avg), 1):\n",
    "    if i in np.argsort(final_all_feat_avg)[-5:]:\n",
    "        print(f\"  {feat}: {w:.4f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "c477efd1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "==================== Fold 1 ====================\n",
      "[Epoch 001] total_loss=5.2695 | ce_loss=0.6674 | sparse_loss=0.4602 | val_acc=0.5714 | val_f1=0.4209 (best acc 0.5714)\n",
      "[Epoch 025] total_loss=0.4088 | ce_loss=0.3604 | sparse_loss=0.0048 | val_acc=0.7602 | val_f1=0.7506 (best acc 0.7704)\n",
      "[Epoch 050] total_loss=0.2931 | ce_loss=0.2612 | sparse_loss=0.0032 | val_acc=0.7755 | val_f1=0.7714 (best acc 0.7908)\n",
      "[Epoch 075] total_loss=0.2179 | ce_loss=0.1895 | sparse_loss=0.0028 | val_acc=0.7857 | val_f1=0.7794 (best acc 0.7959)\n",
      "[Epoch 100] total_loss=0.1522 | ce_loss=0.1243 | sparse_loss=0.0028 | val_acc=0.7908 | val_f1=0.7890 (best acc 0.8010)\n",
      "[Epoch 125] total_loss=0.1282 | ce_loss=0.1033 | sparse_loss=0.0025 | val_acc=0.7959 | val_f1=0.7944 (best acc 0.8112)\n",
      "Early stop at epoch 134, best val Acc=0.8112\n",
      "\n",
      "[Fold Best] Top5 Features (Attention Weight):\n",
      "  1. Base-pKa: 0.0210\n",
      "  2. Activate Ester_ChemShift(Cx): 0.0148\n",
      "  3. Base-Mulliken(Nx): 0.0148\n",
      "  4. Activate Ester_Acc. Area (Å²): 0.0118\n",
      "  5. Base-Electrostatic(Nx): 0.0093\n",
      "[Fold 1] Final Acc=0.8112, F1=0.8096\n",
      "\n",
      "==================== Fold 2 ====================\n",
      "[Epoch 001] total_loss=5.3499 | ce_loss=0.6630 | sparse_loss=0.4687 | val_acc=0.5641 | val_f1=0.4209 (best acc 0.5641)\n",
      "[Epoch 025] total_loss=0.3891 | ce_loss=0.3361 | sparse_loss=0.0053 | val_acc=0.7487 | val_f1=0.7440 (best acc 0.7590)\n",
      "[Epoch 050] total_loss=0.2694 | ce_loss=0.2308 | sparse_loss=0.0039 | val_acc=0.7795 | val_f1=0.7787 (best acc 0.7846)\n",
      "[Epoch 075] total_loss=0.1818 | ce_loss=0.1493 | sparse_loss=0.0032 | val_acc=0.7744 | val_f1=0.7723 (best acc 0.7897)\n",
      "[Epoch 100] total_loss=0.1465 | ce_loss=0.1170 | sparse_loss=0.0029 | val_acc=0.7897 | val_f1=0.7893 (best acc 0.8051)\n",
      "Early stop at epoch 123, best val Acc=0.8051\n",
      "\n",
      "[Fold Best] Top5 Features (Attention Weight):\n",
      "  1. Base-pKa: 0.0255\n",
      "  2. Activate Ester_Mulliken(Hx): 0.0172\n",
      "  3. Base-Mulliken(Nx): 0.0157\n",
      "  4. Activate Ester_Electrostatic(Ox): 0.0141\n",
      "  5. Activate Ester_Natural(Cy): 0.0104\n",
      "[Fold 2] Final Acc=0.8051, F1=0.8053\n",
      "\n",
      "==================== Fold 3 ====================\n",
      "[Epoch 001] total_loss=5.4974 | ce_loss=0.6775 | sparse_loss=0.4820 | val_acc=0.6667 | val_f1=0.6119 (best acc 0.6667)\n",
      "[Epoch 025] total_loss=0.4572 | ce_loss=0.4080 | sparse_loss=0.0049 | val_acc=0.7846 | val_f1=0.7806 (best acc 0.7846)\n",
      "[Epoch 050] total_loss=0.3208 | ce_loss=0.2848 | sparse_loss=0.0036 | val_acc=0.8205 | val_f1=0.8187 (best acc 0.8205)\n",
      "[Epoch 075] total_loss=0.2289 | ce_loss=0.1969 | sparse_loss=0.0032 | val_acc=0.8154 | val_f1=0.8133 (best acc 0.8359)\n",
      "Early stop at epoch 98, best val Acc=0.8359\n",
      "\n",
      "[Fold Best] Top5 Features (Attention Weight):\n",
      "  1. Base-pKa: 0.0255\n",
      "  2. Activate Ester_ChemShift(Cx): 0.0218\n",
      "  3. Activate Ester_Min LocIonPot (kJ/mol): 0.0155\n",
      "  4. Activate Ester_Acc. Area (Å²): 0.0136\n",
      "  5. Activate Ester_Mulliken(Hx): 0.0132\n",
      "[Fold 3] Final Acc=0.8359, F1=0.8328\n",
      "\n",
      "==================== Fold 4 ====================\n",
      "[Epoch 001] total_loss=5.3027 | ce_loss=0.6879 | sparse_loss=0.4615 | val_acc=0.7538 | val_f1=0.7457 (best acc 0.7538)\n",
      "[Epoch 025] total_loss=0.4566 | ce_loss=0.4066 | sparse_loss=0.0050 | val_acc=0.7949 | val_f1=0.7920 (best acc 0.8256)\n",
      "Early stop at epoch 37, best val Acc=0.8256\n",
      "\n",
      "[Fold Best] Top5 Features (Attention Weight):\n",
      "  1. Base-pKa: 0.0865\n",
      "  2. Activate Ester_Mulliken(Hx): 0.0610\n",
      "  3. Base-Mulliken(Nx): 0.0512\n",
      "  4. Activate Ester_ChemShift(Cx): 0.0396\n",
      "  5. Activate Ester_Electrostatic(Ox): 0.0379\n",
      "[Fold 4] Final Acc=0.8256, F1=0.8117\n",
      "\n",
      "==================== Fold 5 ====================\n",
      "[Epoch 001] total_loss=5.3760 | ce_loss=0.6701 | sparse_loss=0.4706 | val_acc=0.6564 | val_f1=0.5430 (best acc 0.6564)\n",
      "[Epoch 025] total_loss=0.3915 | ce_loss=0.3326 | sparse_loss=0.0059 | val_acc=0.8205 | val_f1=0.8182 (best acc 0.8410)\n",
      "Early stop at epoch 47, best val Acc=0.8410\n",
      "\n",
      "[Fold Best] Top5 Features (Attention Weight):\n",
      "  1. Base-pKa: 0.0469\n",
      "  2. Base-Mulliken(Nx): 0.0334\n",
      "  3. Activate Ester_ChemShift(Cx): 0.0292\n",
      "  4. Base-Log P: 0.0246\n",
      "  5. Activate Ester_Mulliken(Hx): 0.0232\n",
      "[Fold 5] Final Acc=0.8410, F1=0.8383\n",
      "\n",
      "==================== CV Summary ====================\n",
      "Accuracy: 0.8238 ± 0.0138\n",
      "Weighted F1: 0.8196 ± 0.0133\n",
      "\n",
      "==================== 稀疏效果统计 ====================\n",
      "总特征数：47\n",
      "权重<0.05的特征数：47\n",
      "权重接近0的特征比例：100.00%\n",
      "权重前5的特征：\n",
      "  Activate Ester_Dipole (debye): 0.0072\n",
      "  Activate Ester_Polarizability: 0.0091\n",
      "  Activate Ester_Natural(Cx): 0.0060\n",
      "  Activate Ester_Mulliken(Bondw): 0.0097\n",
      "  Base-Electrostatic(Nx): 0.0071\n"
     ]
    }
   ],
   "source": [
    "# 交叉验证（加入sparse_lambda参数，核心调参项）\n",
    "kf = KFold(n_splits=5, shuffle=True, random_state=SEED)\n",
    "fold_metrics = []\n",
    "all_feat_avg_weights = []  # 存储每折所有特征的平均权重，用于后续统计\n",
    "sparse_lambda = 10  # 稀疏惩罚系数（关键超参，建议尝试1e-4~1e-2）\n",
    "\n",
    "for i, (tr_idx, val_idx) in enumerate(kf.split(X), 1):\n",
    "    print(f\"\\n==================== Fold {i} ====================\")\n",
    "    X_tr, y_tr = X[tr_idx], y[tr_idx]\n",
    "    X_val, y_val = X[val_idx], y[val_idx]\n",
    "    \n",
    "    # 训练时传入稀疏惩罚系数\n",
    "    model, scaler, best_acc, top5_feat, top5_w, avg_attn = train_one_fold(\n",
    "        X_tr, y_tr, X_val, y_val,\n",
    "        feature_names=feature_cols,\n",
    "        num_classes=num_classes,\n",
    "        epochs=300,\n",
    "        batch_size=32,\n",
    "        lr=1e-3,\n",
    "        patience=30,\n",
    "        sparse_lambda=sparse_lambda  # 控制稀疏性\n",
    "    )\n",
    "    \n",
    "    # 验证集评估（不变）\n",
    "    X_val_s = scaler.transform(X_val)\n",
    "    with torch.no_grad():\n",
    "        logits, _ = model(torch.from_numpy(X_val_s).to(DEVICE))\n",
    "        y_pred = torch.argmax(logits, dim=1).cpu().numpy()\n",
    "    acc, f1 = accuracy_score(y_val, y_pred), f1_score(y_val, y_pred, average='weighted')\n",
    "    fold_metrics.append((acc, f1))\n",
    "    all_feat_avg_weights.append(avg_attn)  # 收集当前折所有特征的平均权重\n",
    "    print(f\"[Fold {i}] Final Acc={acc:.4f}, F1={f1:.4f}\")\n",
    "\n",
    "# 交叉验证结果汇总\n",
    "print(\"\\n==================== CV Summary ====================\")\n",
    "acc_list = [m[0] for m in fold_metrics]\n",
    "f1_list = [m[1] for m in fold_metrics]\n",
    "print(f\"Accuracy: {np.mean(acc_list):.4f} ± {np.std(acc_list):.4f}\")\n",
    "print(f\"Weighted F1: {np.mean(f1_list):.4f} ± {np.std(f1_list):.4f}\")\n",
    "\n",
    "# -------------------------- 验证稀疏效果：统计权重接近0的特征比例 --------------------------\n",
    "# 计算所有折中特征的平均权重（最终权重）\n",
    "final_all_feat_avg = np.mean(all_feat_avg_weights, axis=0)  # (d_in,)\n",
    "# 定义“接近0”的阈值（如权重<0.05视为接近0）\n",
    "zero_threshold = 0.05\n",
    "zero_feat_count = sum(final_all_feat_avg < zero_threshold)\n",
    "zero_feat_ratio = zero_feat_count / len(final_all_feat_avg)\n",
    "\n",
    "print(f\"\\n==================== 稀疏效果统计 ====================\")\n",
    "print(f\"总特征数：{len(final_all_feat_avg)}\")\n",
    "print(f\"权重<{zero_threshold}的特征数：{zero_feat_count}\")\n",
    "print(f\"权重接近0的特征比例：{zero_feat_ratio:.2%}\")\n",
    "print(f\"权重前5的特征：\")\n",
    "for i, (feat, w) in enumerate(zip(feature_cols, final_all_feat_avg), 1):\n",
    "    if i in np.argsort(final_all_feat_avg)[-5:]:\n",
    "        print(f\"  {feat}: {w:.4f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4944373c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "所有特征平均注意力权重（前10名）：\n",
      "                            feature_name  avg_attn_weight\n",
      "0                               Base-pKa         0.041104\n",
      "1                      Base-Mulliken(Nx)         0.025493\n",
      "2            Activate Ester_Mulliken(Hx)         0.023913\n",
      "3           Activate Ester_ChemShift(Cx)         0.021359\n",
      "4          Activate Ester_Acc. Area (Å²)         0.014448\n",
      "5       Activate Ester_Electrostatic(Ox)         0.013127\n",
      "6  Activate Ester_Min LocIonPot (kJ/mol)         0.012415\n",
      "7             Activate Ester_Natural(Cy)         0.011423\n",
      "8                             Base-Log P         0.010855\n",
      "9      Activate Ester_Min ElPot (kJ/mol)         0.009808\n",
      "\n",
      "所有特征平均注意力权重（后10名）：\n",
      "                           feature_name  avg_attn_weight\n",
      "37  Activate Ester_ExposedArea(Ox) (Å²)         0.005482\n",
      "38                 Activate Ester_Log P         0.005270\n",
      "39       Activate Ester_Length(Bondz) Å         0.005226\n",
      "40           Activate Ester_Natural(Ox)         0.005160\n",
      "41               Solvent_Viscosity (cP)         0.005065\n",
      "42          Solvent_Dielectric constant         0.004846\n",
      "43         Activate Ester_ChemShift(Ox)         0.004836\n",
      "44  Activate Ester_ExposedArea(Cx) (Å²)         0.004752\n",
      "45             Solvent_Refractive index         0.004700\n",
      "46           Activate Ester_E LUMO (eV)         0.004523\n",
      "\n",
      "总计特征数：47\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 24179 (\\N{CJK UNIFIED IDEOGRAPH-5E73}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 22343 (\\N{CJK UNIFIED IDEOGRAPH-5747}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 27880 (\\N{CJK UNIFIED IDEOGRAPH-6CE8}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 24847 (\\N{CJK UNIFIED IDEOGRAPH-610F}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 21147 (\\N{CJK UNIFIED IDEOGRAPH-529B}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 26435 (\\N{CJK UNIFIED IDEOGRAPH-6743}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 37325 (\\N{CJK UNIFIED IDEOGRAPH-91CD}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 29305 (\\N{CJK UNIFIED IDEOGRAPH-7279}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 24449 (\\N{CJK UNIFIED IDEOGRAPH-5F81}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 21517 (\\N{CJK UNIFIED IDEOGRAPH-540D}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 31216 (\\N{CJK UNIFIED IDEOGRAPH-79F0}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 25152 (\\N{CJK UNIFIED IDEOGRAPH-6240}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 26377 (\\N{CJK UNIFIED IDEOGRAPH-6709}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 21442 (\\N{CJK UNIFIED IDEOGRAPH-53C2}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 25968 (\\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 30340 (\\N{CJK UNIFIED IDEOGRAPH-7684}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 65288 (\\N{FULLWIDTH LEFT PARENTHESIS}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 24635 (\\N{CJK UNIFIED IDEOGRAPH-603B}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 35745 (\\N{CJK UNIFIED IDEOGRAPH-8BA1}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 20010 (\\N{CJK UNIFIED IDEOGRAPH-4E2A}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "/tmp/ipykernel_27443/3947418826.py:132: UserWarning: Glyph 65289 (\\N{FULLWIDTH RIGHT PARENTHESIS}) missing from font(s) DejaVu Sans.\n",
      "  plt.tight_layout()\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 29305 (\\N{CJK UNIFIED IDEOGRAPH-7279}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 24449 (\\N{CJK UNIFIED IDEOGRAPH-5F81}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 21517 (\\N{CJK UNIFIED IDEOGRAPH-540D}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 31216 (\\N{CJK UNIFIED IDEOGRAPH-79F0}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 25152 (\\N{CJK UNIFIED IDEOGRAPH-6240}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 26377 (\\N{CJK UNIFIED IDEOGRAPH-6709}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 21442 (\\N{CJK UNIFIED IDEOGRAPH-53C2}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 25968 (\\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 30340 (\\N{CJK UNIFIED IDEOGRAPH-7684}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 24179 (\\N{CJK UNIFIED IDEOGRAPH-5E73}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 22343 (\\N{CJK UNIFIED IDEOGRAPH-5747}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 27880 (\\N{CJK UNIFIED IDEOGRAPH-6CE8}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 24847 (\\N{CJK UNIFIED IDEOGRAPH-610F}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 21147 (\\N{CJK UNIFIED IDEOGRAPH-529B}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 26435 (\\N{CJK UNIFIED IDEOGRAPH-6743}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 37325 (\\N{CJK UNIFIED IDEOGRAPH-91CD}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 65288 (\\N{FULLWIDTH LEFT PARENTHESIS}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 24635 (\\N{CJK UNIFIED IDEOGRAPH-603B}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 35745 (\\N{CJK UNIFIED IDEOGRAPH-8BA1}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 20010 (\\N{CJK UNIFIED IDEOGRAPH-4E2A}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "/tmp/ipykernel_27443/3947418826.py:135: UserWarning: Glyph 65289 (\\N{FULLWIDTH RIGHT PARENTHESIS}) missing from font(s) DejaVu Sans.\n",
      "  plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: WenQuanYi Zen Hei, SimHei, Arial Unicode MS\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "所有参数注意力权重图表已保存为：all_features_avg_attn_weights.png\n",
      "所有特征权重排序表已保存为：all_features_attn_weight_ranking.xlsx\n"
     ]
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "# -------------------------- 1. 核心前提：获取所有特征的平均注意力权重 --------------------------\n",
    "# （需确保分类模型已训练完成，且有训练好的最佳模型 + 特征名称列表）\n",
    "# 关键逻辑：用全量数据（或验证集）计算每个特征在所有样本上的注意力权重均值，覆盖所有参数\n",
    "\n",
    "def get_all_features_avg_attn(model, scaler, X_all, feature_names, device, batch_size=256):\n",
    "    \"\"\"\n",
    "    计算所有特征的平均注意力权重\n",
    "    Args:\n",
    "        model: 训练好的分类模型（带FeatureAttention）\n",
    "        scaler: 数据标准化器（训练时拟合的）\n",
    "        X_all: 全量特征数据（numpy数组）\n",
    "        feature_names: 所有特征的名称列表\n",
    "        device: 计算设备（cuda/cpu）\n",
    "        batch_size: 批处理大小（避免内存溢出）\n",
    "    Returns:\n",
    "        DataFrame: 包含特征名、平均注意力权重，已按权重排序\n",
    "    \"\"\"\n",
    "    model.eval()  # 模型设为评估模式\n",
    "    all_attn_weights = []  # 存储所有样本的注意力权重\n",
    "    \n",
    "    # 批处理计算（避免全量数据一次性入内存）\n",
    "    with torch.no_grad():\n",
    "        for i in range(0, len(X_all), batch_size):\n",
    "            # 取当前批次数据并标准化\n",
    "            X_batch = X_all[i:i+batch_size]\n",
    "            X_batch_s = scaler.transform(X_batch)\n",
    "            X_batch_tensor = torch.from_numpy(X_batch_s).to(device)\n",
    "            \n",
    "            # 前向传播，仅获取注意力权重\n",
    "            _, attn_w = model(X_batch_tensor)  # attn_w: (batch_size, num_features)\n",
    "            all_attn_weights.append(attn_w.cpu().numpy())\n",
    "    \n",
    "    # 计算所有样本的特征权重均值（按特征维度取平均）\n",
    "    all_attn_weights = np.concatenate(all_attn_weights, axis=0)  # (total_samples, num_features)\n",
    "    avg_attn_weights = np.mean(all_attn_weights, axis=0)  # (num_features,)：每个特征的平均权重\n",
    "    \n",
    "    # # 整理为DataFrame并按权重降序排序\n",
    "    # feat_attn_df = pd.DataFrame({\n",
    "    #     'feature_name': feature_names,\n",
    "    #     'avg_attn_weight': avg_attn_weights\n",
    "    # }).sort_values(by='avg_attn_weight', ascending=False).reset_index(drop=True)\n",
    "\n",
    "    # 生成稀疏惩罚后的权重可视化\n",
    "    feat_attn_df = pd.DataFrame({\n",
    "        'feature_name': feature_cols,\n",
    "        'avg_attn_weight': final_all_feat_avg\n",
    "    }).sort_values(by='avg_attn_weight', ascending=False).reset_index(drop=True)\n",
    "\n",
    "# 后续可视化代码与之前一致（横向柱状图）\n",
    "# ...（此处省略可视化代码，直接复用之前的“所有参数注意力权重”绘图逻辑）\n",
    "    \n",
    "    return feat_attn_df\n",
    "\n",
    "# -------------------------- 2. 计算所有特征的平均权重（衔接已有代码）--------------------------\n",
    "# 注意：此处使用训练好的模型和标准化器（以交叉验证中最后一折的模型为例，或用最优折模型）\n",
    "# 若需更稳定结果，可使用所有折模型的权重均值，此处简化为单模型（实际可根据需求调整）\n",
    "# （假设之前交叉验证后，model和scaler为最后一折的最佳模型和标准化器）\n",
    "feat_attn_df = get_all_features_avg_attn(\n",
    "    model=model,  # 训练好的分类模型\n",
    "    scaler=scaler,  # 数据标准化器\n",
    "    X_all=X,  # 全量特征数据（原代码中的X）\n",
    "    feature_names=feature_cols,  # 所有特征的名称列表（原代码中的feature_cols）\n",
    "    device=DEVICE,  # 计算设备\n",
    "    batch_size=256\n",
    ")\n",
    "\n",
    "# 查看前10个和后10个特征的权重（验证结果合理性）\n",
    "print(\"所有特征平均注意力权重（前10名）：\")\n",
    "print(feat_attn_df.head(10))\n",
    "print(\"\\n所有特征平均注意力权重（后10名）：\")\n",
    "print(feat_attn_df.tail(10))\n",
    "print(f\"\\n总计特征数：{len(feat_attn_df)}\")\n",
    "\n",
    "# -------------------------- 3. 可视化所有参数的平均注意力权重 --------------------------\n",
    "# 设置中文字体（避免中文乱码）\n",
    "plt.rcParams['font.sans-serif'] = ['WenQuanYi Zen Hei', 'SimHei', 'Arial Unicode MS']\n",
    "plt.rcParams['axes.unicode_minus'] = False\n",
    "\n",
    "# 定义图表样式（横向柱状图，按权重降序排列，支持特征数较多的场景）\n",
    "fig, ax = plt.subplots(figsize=(10, len(feat_attn_df)*0.2))  # 高度随特征数自适应\n",
    "\n",
    "# 绘制横向柱状图（y轴为特征名，x轴为平均权重）\n",
    "bars = ax.barh(\n",
    "    y=feat_attn_df['feature_name'],  # y轴：特征名（按权重降序）\n",
    "    width=feat_attn_df['avg_attn_weight'],  # x轴：平均注意力权重\n",
    "    color=plt.cm.viridis(feat_attn_df['avg_attn_weight']/feat_attn_df['avg_attn_weight'].max()),  # 渐变色（权重越高颜色越深）\n",
    "    alpha=0.8,\n",
    "    edgecolor='white',\n",
    "    linewidth=0.5\n",
    ")\n",
    "\n",
    "# 添加数值标签（在每个柱子右侧显示权重值，仅显示前20个和后10个，避免拥挤）\n",
    "for i, (bar, weight) in enumerate(zip(bars, feat_attn_df['avg_attn_weight'])):\n",
    "    # 仅对前20个（高权重）和后10个（低权重）特征添加标签，中间特征省略（避免图表杂乱）\n",
    "    if i < 20 or i >= len(feat_attn_df) - 10:\n",
    "        ax.text(\n",
    "            x=bar.get_width() + 0.005,  # 标签在柱子右侧，留0.005间距\n",
    "            y=bar.get_y() + bar.get_height()/2,  # 标签垂直居中\n",
    "            s=f'{weight:.3f}',  # 权重值保留3位小数\n",
    "            ha='left',\n",
    "            va='center',\n",
    "            fontsize=8,\n",
    "            fontweight='bold',\n",
    "            color='darkslategrey'\n",
    "        )\n",
    "\n",
    "# 设置坐标轴与标题\n",
    "ax.set_xlabel('平均注意力权重', fontsize=12, fontweight='bold', labelpad=10)\n",
    "ax.set_ylabel('特征名称', fontsize=12, fontweight='bold', labelpad=10)\n",
    "ax.set_title(\n",
    "    f'所有参数的平均注意力权重（总计{len(feat_attn_df)}个特征）',\n",
    "    fontsize=14, fontweight='bold', pad=20\n",
    ")\n",
    "\n",
    "# 调整x轴范围（留10%余量，避免右侧标签超出画布）\n",
    "x_max = feat_attn_df['avg_attn_weight'].max()\n",
    "ax.set_xlim(0, x_max * 1.1)\n",
    "\n",
    "# 调整y轴标签字体大小（特征数多时自动缩小）\n",
    "ax.tick_params(axis='y', labelsize=8 if len(feat_attn_df) > 30 else 10)\n",
    "ax.tick_params(axis='x', labelsize=10)\n",
    "\n",
    "# 添加网格线（x轴方向，辅助判断权重大小）\n",
    "ax.grid(axis='x', alpha=0.3, linestyle='--', linewidth=0.5)\n",
    "ax.set_axisbelow(True)  # 网格线在柱子下方\n",
    "\n",
    "# 调整布局（避免标签被截断）\n",
    "plt.tight_layout()\n",
    "\n",
    "# 保存图片（高分辨率，支持放大查看细节）\n",
    "plt.savefig('all_features_avg_attn_weights.png', dpi=300, bbox_inches='tight')\n",
    "plt.close()\n",
    "\n",
    "print(\"\\n所有参数注意力权重图表已保存为：all_features_avg_attn_weights.png\")\n",
    "\n",
    "# -------------------------- 4. 可选：输出权重排序表（便于后续分析）--------------------------\n",
    "# 保存所有特征的权重排序结果到Excel，支持进一步筛选\n",
    "feat_attn_df['rank'] = range(1, len(feat_attn_df)+1)  # 添加排名列\n",
    "feat_attn_df.to_excel('all_features_attn_weight_ranking.xlsx', index=False)\n",
    "print(\"所有特征权重排序表已保存为：all_features_attn_weight_ranking.xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1dca3555",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "BNN",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.23"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
